﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using JQuery.Net.UI;
using System.Collections;
using System.Collections.Specialized;
using System.Web.UI;

namespace JQuery.Net
{
    /// <summary>
    /// This is a JqNet Attribuate collection
    /// </summary>
    /// <remarks>
    /// this collection was built to avoid using the view state container.
    /// </remarks>
    public class jQNetAttributeCollection
    {
        private jQNetControl Control;
        private IDictionary Table;

        #region constructor
        public jQNetAttributeCollection(jQNetControl ctrl)
        {
            CssStyles = new CssStyleCollection();
            Table = new HybridDictionary();

            Control = ctrl;
        }
        #endregion

        public string this[string key]
        {
            get
            {
                string value = (string)Table[key];

                return value;
            }
            set
            {
                if (key.Eq("style"))
                    CssStyles.Value = value;
                else
                    Table[key] = value;
            }
        }

        public CssStyleCollection CssStyles { get; protected set; }

        public ICollection Keys { get { return Table.Keys; } }

        public void Render(HtmlTextWriter oWriter)
        {
            if (CssStyles.Count > 0)
                Table["style"] = CssStyles.Value;

            foreach (DictionaryEntry entry in Table)
            {
                oWriter.WriteAttribute((string)entry.Key, (string)entry.Value);
            }
        }
    }
}
